package com.huohuo.springdemo.beanLife;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 *SpringBean生命周期
 * bean 实现了BeanNameAware接口，并重写了setBeanName()方法
 */
@Component

public class SpringBeanLife implements BeanNameAware,BeanFactoryAware,ApplicationContextAware{

    private String beanName;



    @Override
    public void setBeanName(String s) {
         this.beanName = s;
        System.out.println("======="+s);//如果为指定bean的id，打印：================springBeanLife

    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("-------:"+beanFactory);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("*******:"+applicationContext.getBean( this.beanName).hashCode());
    }


}
